package com.hhit.bigscreenbackmanage.service.impl.tgygl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.dao.tgygl.TTgyglProjectProcessMapper;
import com.hhit.bigscreenbackmanage.service.tgygl.TTgyglProjectProcessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TTgyglProjectProcessServiceImpl implements TTgyglProjectProcessService {

    private Logger log = LoggerFactory.getLogger(TTgyglProjectProcessServiceImpl.class);

    @Autowired
    TTgyglProjectProcessMapper tTgyglProjectProcessMapper;

    @Override
    public Map<String, Object> queryYchlzCount(JSONObject jsonObject) throws Exception {
        if(jsonObject.get("dataTime") == null || "".equals(jsonObject.get("dataTime"))){
            throw new Exception("缺少必要参数: dataTime");
        }
        Map<String, Object> result = new HashMap<>();
        result.put("cp",0);
        result.put("zj",0);
        result.put("tj",0);
        result.put("dq",0);
        result.put("tssy",0);
        result.put("jdjgc",0);
        result.put("sjxmb",0);
        result.put("jlxmb",0);
        result.put("sgry",0);

        jsonObject.put("project","虞城");
        List<Map<String,String>> data = new ArrayList<>();
        try{
            data = tTgyglProjectProcessMapper.queryProjectProcessList(jsonObject);
        }catch (Exception e){
            log.error(e.getMessage());
            throw new Exception("数据库内部错误");
        }

        for(Map<String,String> map : data){
            if(map.get("attribute").indexOf("场平") >= 0){
                result.put("cp",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("桩建") >= 0){
                result.put("zj",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("土建") >= 0){
                result.put("tj",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("电气") >= 0){
                result.put("dq",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("调试") >= 0){
                result.put("tssy",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("地极") >= 0){
                result.put("jdjgc",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("设计") >= 0){
                result.put("sjxmb",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("监理") >= 0){
                result.put("jlxmb",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("施工") >= 0){
                result.put("sgry",map.get("value"));
            }
        }

        return result;
    }

    @Override
    public Map<String, Object> queryZlxlgcOrJdjgcOrScgcCount(JSONObject jsonObject) throws Exception {
        if(jsonObject.get("dataTime") == null || "".equals(jsonObject.get("dataTime"))){
            throw new Exception("缺少必要参数: dataTime");
        }
        if(jsonObject.get("project") == null || "".equals(jsonObject.get("project"))){
            throw new Exception("缺少必要参数: project");
        }
        Map<String, Object> result = new HashMap<>();
        result.put("jinczs",0);
        result.put("jincwc",0);
        result.put("jincbl",0);
        result.put("jiczs",0);
        result.put("jicwc",0);
        result.put("jicbl",0);
        result.put("ltzs",0);
        result.put("ltwc",0);
        result.put("ltbl",0);
        result.put("jxzs",0);
        result.put("jxwc",0);
        result.put("jxbl",0);

        List<Map<String,String>> data = new ArrayList<>();
        try{
            data = tTgyglProjectProcessMapper.queryProjectProcessList(jsonObject);
        }catch (Exception e){
            log.error(e.getMessage());
            throw new Exception("数据库内部错误");
        }

        for(Map<String,String> map:data){
            if(map.get("attribute").indexOf("进场总数") >= 0){
                result.put("jinczs",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("进场完成") >= 0){
                result.put("jincwc",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("进场比例") >= 0){
                result.put("jincbl",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("基础总数") >= 0){
                result.put("jiczs",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("基础完成") >= 0){
                result.put("jicwc",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("基础比例") >= 0){
                result.put("jicbl",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("立塔总数") >= 0){
                result.put("ltzs",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("立塔完成") >= 0){
                result.put("ltwc",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("立塔比例") >= 0){
                result.put("ltbl",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("架线总数") >= 0){
                result.put("jxzs",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("架线完成") >= 0){
                result.put("jxwc",map.get("value"));continue;
            }
            if(map.get("attribute").indexOf("架线比例") >= 0){
                result.put("jxbl",map.get("value"));
            }
        }
        return result;
    }

    @Override
    public Map<String, Object> queryBdzgkjgcCount(JSONObject jsonObject) throws Exception {
        if(jsonObject.get("dataTime") == null || "".equals(jsonObject.get("dataTime"))){
            throw new Exception("缺少必要参数: dataTime");
        }
        Map<String, Object> result = new HashMap<>();
        result.put("wqjc",0);
        result.put("jcq",0);
        result.put("jdqxs",0);
        result.put("GIS",0);

        jsonObject.put("project","改扩建");
        List<Map<String,String>> data = new ArrayList<>();
        try{
            data = tTgyglProjectProcessMapper.queryProjectProcessList(jsonObject);
        }catch (Exception e){
            log.error(e.getMessage());
            throw new Exception("数据库内部错误");
        }

        for(Map<String,String> map : data) {
            if (map.get("attribute").indexOf("围墙基础") >= 0) {
                result.put("wqjc", map.get("value"));
                continue;
            }
            if (map.get("attribute").indexOf("基础墙") >= 0) {
                result.put("jcq", map.get("value"));
                continue;
            }
            if (map.get("attribute").indexOf("继电器") >= 0) {
                result.put("jdqxs", map.get("value"));
                continue;
            }
            if (map.get("attribute").indexOf("GIS") >= 0) {
                result.put("GIS", map.get("value"));
            }
        }

        return result;
    }


}
